package com.dd.cloud.user.service.menu.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dd.cloud.common.constants.ClientMenuConstants;
import com.dd.cloud.user.entity.menu.ClientMenu;
import com.dd.cloud.user.entity.menu.ClientMenuUser;
import com.dd.cloud.user.mapper.menu.ClientMenuUserMapper;
import com.dd.cloud.user.service.menu.IClientMenuUserService;
import com.dd.cloud.common.vo.LoginInfo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 客户端菜单用户配置表 服务实现类
 * </p>
 *
 * @author czg
 * @since 2022-05-07
 */
@Service
public class ClientMenuUserServiceImpl extends ServiceImpl<ClientMenuUserMapper, ClientMenuUser> implements IClientMenuUserService {

    /**
     * 获取当前客户端用户的可用菜单
     *
     * @return
     */
    @Override
    public List<ClientMenu> getClientMenuUserList(LoginInfo loginInfo, String client) {

        List<ClientMenu> list = getBaseMapper().getClientMenuUserList(loginInfo.getId(), loginInfo.getType(), client);
        if ((list == null || list.isEmpty())) {
            list = getBaseMapper().getClientMenuUserList(loginInfo.getMechanId(), LoginInfo.UserType.MECHAN, client);
        }
        if ((list == null || list.isEmpty())) {
            list = getBaseMapper().getClientMenuUserList(ClientMenuConstants.Whole.TYPE, ClientMenuConstants.Whole.TYPE, client);
        }
        return list;
    }
}
